// components/good/good.js
import util from '../../utils/utils'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    couponInfo: Object, // 商品信息
    buttonText: String,
    bgColor:String,
    show: {
      type: Boolean,
      value: true
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    isShowUseRule: false
  },

  /**
   * 组件的方法列表
   */
  methods: {
    //点击使用规则
    onShowUseRule() {
      console.log(this.data.bgColor)
      this.setData({
        isShowUseRule: !this.data.isShowUseRule
      })
    },
    // 点击立即使用
    onUseCoupon(e) {
      const app = getApp()
      let data = e.currentTarget.dataset;
      console.log(e)
      let item = data.couponinfo;
      let gid = item.hasOwnProperty('goods_id') ? item['goods_id'] : 0;
      app.globalData.couponInfo = item;
      if (gid > 0) {
        util.toPage('/pages/goods/mmallGoodsDetails/mmallGoodsDetails?id=' + gid);
      } else {
        util.toPage({
          currentTarget: {
            dataset: {
              page: '/pages/home/index/index?type=nearby',
              type: "tabar"
            }
          }
        }, false, true);
      }
    },

  }
});